package com.ruoyi.subject.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.subject.domain.SubjectTask;
import com.ruoyi.subject.service.ISubjectTaskService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课题项目Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("课题项目管理")
@RestController
@RequestMapping("/subject/task")
public class SubjectTaskController extends BaseController
{
    @Autowired
    private ISubjectTaskService subjectTaskService;

    /**
     * 查询课题项目列表
     */
    @ApiOperation("查询课题项目列表")   
    @GetMapping("select")
    public TableDataInfo select(SubjectTask subjectTask)
    {
        startPage();
        List<SubjectTask> list = subjectTaskService.selectSubjectTaskList(subjectTask);
        return getDataTable(list);
    }
    
    /**
     * 查询课题项目列表
     */
    @ApiOperation("查询课题项目列表")   
    @GetMapping("my")
    public TableDataInfo my(SubjectTask subjectTask)
    {
    	subjectTask.setMasterUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<SubjectTask> list = subjectTaskService.selectSubjectTaskList(subjectTask);
        return getDataTable(list);
    }
    
    /**
     * 查询课题项目列表
     */
    @ApiOperation("查询课题项目列表")   
    @PreAuthorize("@ss.hasPermi('subject:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubjectTask subjectTask)
    {
        startPage();
        List<SubjectTask> list = subjectTaskService.selectSubjectTaskList(subjectTask);
        return getDataTable(list);
    }

    /**
     * 导出课题项目列表
     */
    @ApiOperation("导出课题项目列表")    
    @PreAuthorize("@ss.hasPermi('subject:task:export')")
    @Log(title = "课题项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SubjectTask subjectTask)
    {
        List<SubjectTask> list = subjectTaskService.selectSubjectTaskList(subjectTask);
        ExcelUtil<SubjectTask> util = new ExcelUtil<SubjectTask>(SubjectTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 获取课题项目详细信息
     */
    @ApiOperation("获取课题项目详细信息")
    @ApiImplicitParam(name = "id", value = "课题项目ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('subject:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(subjectTaskService.selectSubjectTaskById(id));
    }

    /**
     * 新增课题项目
     */
    @ApiOperation("新增课题项目")
    @PreAuthorize("@ss.hasPermi('subject:task:add')")
    @Log(title = "课题项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubjectTask subjectTask)
    {
        return toAjax(subjectTaskService.insertSubjectTask(subjectTask));
    }

    /**
     * 修改课题项目
     */
    @ApiOperation("修改课题项目")  
    @PreAuthorize("@ss.hasPermi('subject:task:edit')")
    @Log(title = "课题项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectTask subjectTask)
    {
        return toAjax(subjectTaskService.updateSubjectTask(subjectTask));
    }

    /**
     * 删除课题项目
     */
    @ApiOperation("删除课题项目")
    @ApiImplicitParam(name = "id", value = "课题项目ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('subject:task:remove')")
    @Log(title = "课题项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subjectTaskService.deleteSubjectTaskByIds(ids));
    }
}
